import Category from './CategoryEnum'

class ItemData {
    id!: number;
    categoryId!: Category;
    title!: string;
    content!: string;
    createTime!: string;

    constructor(
        id: number = -1,
        categoryId: Category = -1,
        title: string = '',
        content: string = '') {

        this.id = id;
        this.categoryId = categoryId;
        this.title = title;
        this.content = content;
        this.createTime = this.formatTime(Date.now());
    }

    /**
     * 转换时间格式
     * 
     * @param timestamp 
     */
    formatTime(timestamp: number): string {
        let date = new Date(timestamp);
        let str = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes();
        return str;
    }

}

export default ItemData;